/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.prototype.console;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;

/**.
 * Treat the file config to build the SourceForge path with user criterias
 * @author mdcolin
 */


public class CriteriaFile {
    /**.
     * @param filename
     */
    private String filename;

    /**.
     * Constructor
     * @param newFileName
     */
    public CriteriaFile(final String newFileName) {
        this.filename = newFileName;
    }

    /**.
     * Load the config file
     * @return the properties object
     * @throws FileNotFoundException
     * @throws IOException
     */
    public Properties readCriteria() throws IOException {
            Properties properties = new Properties();
            FileInputStream input = new FileInputStream(getFilename());
        try {
            properties.load(input);
            return properties;
        } finally {
           input.close();
        }
    }
    /**.
     * Make the link to find programs
     * @return the path with the different criterias
     * @throws FileNotFoundException
     * @throws IOException
     */
    public String urlCriteria(){
        String path = "";
        try {
            Enumeration element = this.readCriteria().elements();
            Enumeration key = this.readCriteria().keys();

            while (element.hasMoreElements()) {
                Object el = element.nextElement();
                Object ke = key.nextElement();

                if (!el.equals("") && !ke.equals("")) {
                    if (!path.equals("")) {
                        path = path + "/" + ke + ":" + el;
                    } else {
                        path = ke + ":" + el;
                    }
                }
            }
        } catch (Exception ex) {
            ex.getMessage();
        }
        return path;
    }

    /**.
     * @return filename
     */
    public String getFilename() {
        return filename;
    }

    /**.
     * @param filename
     */
    public void setFilename(String filename) {
        this.filename = filename;
    }
}
